(
  function () {
    var myurl = window.location.href;

    function GetRequest() {
      var e = location.href;
      var f = {};
      if (e.indexOf("?") != -1) {
        var g = e.substr(e.indexOf("?") + 1);
        g = g.split("&");
        for (var h = 0; h < g.length; h++) {
          f[g[h].split("=")[0]] = decodeURI(g[h].split("=")[1]);
        }
      }
      return f;
    }


    function shareNum() {
      $.ajax({
        type: 'get',
        url: 'http://wxjx.unisk.cn/wxjx/goddess/common/share/updateShareNum',
        data: '',
        success: function (result) {

        }
      })
    }
    wx.ready(function () {
      var title = "vivo 多款手机、500元智能礼包等你来拿！";
      var descT = "女神活动不见不散~";
      var desc = "女神活动来袭！vivo 多款手机、500元智能礼包等你来拿~";
      var userid = '';
      if (Boolean(GetRequest().userid)) {
        userid = GetRequest().userid;
      }
      var link = 'http://wxjx.unisk.cn/wxjx/goddess/common/share/toShare?id=' + userid;
      var imgUrl = "http://wxjx.unisk.cn/pages/2018/wxjx/schoolBeautyGirl/static/img/flower.png";

      //分享到朋友圈
      wx.onMenuShareTimeline({
        title: title, // 分享标题【必填】
        desc: desc, // 分享描述【必填】
        link: link, // 分享链接【必填】
        imgUrl: imgUrl, // 分享图标【必填】
        success: function () {
          // 用户确认分享后执行的回调函数 
          shareNum();
        },
        cancel: function () {
          // 用户取消分享后执行的回调函数
        }
      });

      //分享给好友
      wx.onMenuShareAppMessage({
        title: title, // 分享标题【必填】
        desc: descT, // 分享描述【必填】
        link: link, // 分享链接【必填】
        imgUrl: imgUrl, // 分享图标【必填】
        type: 'link', // 分享类型,music、video或link，不填默认为link【必填】
        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
        success: function () {
          // 用户确认分享后执行的回调函数
          // alert('已分享');
          shareNum();
        },
        cancel: function () {
          // 用户取消分享后执行的回调函数 
          // alert('已取消');
        }
      });

    });

    var appId = "wxf71dfa4539d2f215";
    var nonceStr = "oDxlNmsjqvV9D29r"; //随意
    var timestamp = "1420942347"; //随意

    var signature = null;

    $.ajax({
      url: 'http://wxjx.unisk.cn/weixinjx/WeiXinJxApi/getSignature',
      async: false,
      dataType: "json",
      data: {
        "nonceStr": nonceStr,
        "timestamp": timestamp,
        "url": myurl
      },
      success: function (data) {
        console.log(data);
        signature = data.signature;
        console.log(signature);
      },
      error: function () {
        signature = "error";
      }
    });
    wx.config({
      debug: false,
      appId: appId,
      timestamp: timestamp,
      nonceStr: nonceStr,
      signature: signature,
      jsApiList: [
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem',
        'showAllNonBaseMenuItem',
        'translateVoice',
        'startRecord',
        'stopRecord',
        'onRecordEnd',
        'playVoice',
        'pauseVoice',
        'stopVoice',
        'uploadVoice',
        'downloadVoice',
        'chooseImage',
        'previewImage',
        'uploadImage',
        'downloadImage',
        'getNetworkType',
        'openLocation',
        'getLocation',
        'hideOptionMenu',
        'showOptionMenu',
        'closeWindow',
        'scanQRCode',
        'chooseWXPay',
        'openProductSpecificView',
        'addCard',
        'chooseCard',
        'openCard'
      ]
    });
  }

)();
